package com.lql.aicode.ai;

import com.lql.aicode.utils.SpringContextUtil;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.service.AiServices;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * AI代码生成类型路由服务工厂

 */
@Slf4j
@Configuration
public class AiInterviewGenerateServiceFactory {

    /**
     * 创建AI代码生成类型路由服务实例
     */
    public AiInterviewGenerateService createInterviewGenerateService() {
        // 动态获取多例的路由 ChatModel，支持并发
        ChatModel chatModel = SpringContextUtil.getBean("interviewChatModelPrototype", ChatModel.class);
        return AiServices.builder(AiInterviewGenerateService.class)
                .chatModel(chatModel)
                .build();
    }

    /**
     * 默认提供一个 Bean
     */
    @Bean
    public AiInterviewGenerateService aiInterviewGenerateService() {
        return createInterviewGenerateService();
    }
}
